//
//  ZLWTopicDetailController.m
//  EPA
//
//  Created by lanou3g on 16/4/27.
//  Copyright © 2016年 zlw. All rights reserved.
//

#import "ZLWTopicDetailController.h"
#import "ZLWTopicListController.h"
#import "ZLWUserInfoManager.h"
@interface ZLWTopicDetailController ()<UIWebViewDelegate>
@property (nonatomic, strong) NSString *html;
@end

@implementation ZLWTopicDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
     [self loadNetWorking];
    self.view.backgroundColor = [UIColor redColor];
    // Do any additional setup after loading the view.
}
- (void)loadNetWorking
{
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:webView];
    webView.delegate  = self;
    
    
    [ZLW_NetWorkRequestManager requestURL:[NSURL URLWithString:TOPICINFO_URL ] Method:CK_POST Params:@{@"contentid":self.getmodel.contentid,@"client":@"1",@"deviceid":@"63A94D37-33F9-40FF-9EBB-481182338873",@"auth":[ZLWUserInfoManager shareManager].auth,@"version":@"3.0.2"}
                                   Result:^(NSData *data, NSURLResponse *response, NSError *error) {
                                       NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
                                       NSDictionary *dataDict = jsonDict[@"data"][@"postsinfo"];
                                            dispatch_async(dispatch_get_main_queue(), ^{
                                           [webView loadHTMLString:dataDict[@"html"] baseURL:nil];
                                       });
                                       
                                   }];
}


//将图片大小弄成固定的
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [webView stringByEvaluatingJavaScriptFromString:
     @"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"function ResizeImages() { "
     "var myimg,oldwidth;"
     "var maxwidth=380;" //缩放系数
     "for(i=0;i <document.images.length;i++){"
     "myimg = document.images[i];"
     "if(myimg.width > maxwidth){"
     "oldwidth = myimg.width;"
     "myimg.width = maxwidth;"
     "myimg.height = myimg.height * (maxwidth/oldwidth);"
     "}"
     "}"
     "}\";"
     "document.getElementsByTagName('head')[0].appendChild(script);"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
